import axios from '@/libs/axios1.js';
let jsonHeaders = { 'content-type': 'application/json;charset=UTF-8' };
let proTemplate = '/resource-manager/template'
// 模板列表
export const getTemplateData = (params, query) => {
    return axios({
        // url: `${baseUrl}/virtual/template/list`,
        url: `${proTemplate}/list`,
        method: 'post',
        data: JSON.stringify(params),
        params: query,
        headers: jsonHeaders
    });
};
// 编辑模板
export const modifyTemplate = (params, id) => {
    return axios({
        // url: `${baseUrl}/virtual/template/update/${id}`,
        url: `${proTemplate}/${id}`,
        method: 'put',
        params: params,
        headers: jsonHeaders
    });
};
// 删除模板
export const delTemplate = (id) => {
    return axios({
        // url: `${baseUrl}/virtual/template/delete/${id}`,
        url: `${proTemplate}/${id}`,
        method: 'delete',
        headers: jsonHeaders
    });
};
// 获取模板详情
export const getTempInfpByID = async (id) => {
    let res = await axios({
        url: `${proTemplate}/list`,
        method: 'post',
        params: { pageIndex: 1, pageSize: 1 },
        data: { id: id },
        headers: jsonHeaders
    }).catch((error) => {
        return Promise.reject(error);
    });
    let {
        code,
        data: { items: templates },
        message
    } = res;
    let template = templates.length > 0 ? templates[0] : {};
    return Promise.resolve({ code, data: template, message });
};
// 导出json文件
export const importTemp = (id) => {
    return axios({
        url: `${proTemplate}/file/${id}`,
        method: 'post',
        headers: jsonHeaders
    });
};

// 生成模板
export const templateAutomatic = (data) => {
    return axios({
        url: `${proTemplate}/automatic`,
        method: 'post',
        data: data,
        headers: jsonHeaders
    });
};

//导入模板
export const inPutTemFile = (params) => {
    return axios({
        url: `${proTemplate}/add`,
        method: 'post',
        data: params,
        headers: jsonHeaders
    });
};

export const createTemplate = (data) => {
    return axios({
        url: `${proTemplate}/create`,
        method: 'POST',
        headers: jsonHeaders,
        data
    });
};
